package com.lkcg.demo.api;

import com.lkcg.demo.common.mybatis.PageEntity;
import com.lkcg.demo.common.mybatis.PagingResult;
import com.lkcg.demo.dao.MyTestDAO;
import com.lkcg.demo.service.MyTestService;
import com.lkcg.demo.service.SimpleManageService;
import com.lkcg.demo.utils.api.ResultObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
@Log4j
@Api("测试api")
public class HomeApiController {
    @Autowired
    private SimpleManageService simpleManageService;
    @Autowired
    private MyTestService myTestService;

    @RequestMapping(value = "/home", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "home", notes = "home")
    ResultObject<PagingResult> home() {
        return ResultObject.getResultObject(() -> {
            PageEntity pageEntity = new PageEntity();
            pageEntity.setPage(2);
            pageEntity.setSize(1);
            pageEntity.setParam(new HashMap());
            PagingResult<Object> list = simpleManageService.initObjectDAO(MyTestDAO.class)
                    .getObjectPage(pageEntity);

            myTestService.casInsertTest();
            return list;
        });

    }
}
